import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer' // 引入中间件
import type { StoreInfo } from '@/Interface/StoreInfoInterface'
import { createJSONStorage, persist } from 'zustand/middleware'

type CompareState = {
  cmpData: StoreInfo | null,
  setCmpData: (data: StoreInfo) => void
}

export const useCmpDataStore = create<CompareState>()(
  persist(
    immer((set) => ({
      cmpData: null,
      setCmpData: (data) =>
        set((state) => { state.cmpData = data })
    })),
    {
      name: 'compare-data',
      storage: createJSONStorage(() => sessionStorage),
    }
  )
)